package com.sale.system.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.sale.common.core.domain.R;
import com.sale.common.core.web.controller.BaseController;
import com.sale.common.excel.utils.ExcelUtil;
import com.sale.common.log.annotation.Log;
import com.sale.common.log.enums.BusinessType;
import com.sale.common.mybatis.core.page.PageQuery;
import com.sale.common.mybatis.core.page.TableDataInfo;
import com.sale.system.domain.PullDown;
import com.sale.system.domain.SysAccountManagement;
import com.sale.system.export.SysAccountManagementExport;
import com.sale.system.service.ISysAccountManagementService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @Author: YSL
 * @Date: 2023/7/5 15:35
 * @Desc: 账户管理 控制层接口请求
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/accountManagement")
public class SysAccountManagementController extends BaseController {

    /**
     * 账户管理
     */
    private final ISysAccountManagementService sysAccountManagementService;


    /**
     * 分页获取账户管理列表
     */
    //@SaCheckPermission("system:account:list")
    @GetMapping("/list")
    public TableDataInfo<SysAccountManagement> list(SysAccountManagement sysAccountManagement, PageQuery pageQuery) {
        return sysAccountManagementService.selectAccountManagementList(sysAccountManagement, pageQuery);
    }

    /**
     * 分页获取账户管理列表(状态是启用)
     */
    @GetMapping("/listNotPage")
    public R<?> listNotPage(SysAccountManagement sysAccountManagement) {
        return R.ok(sysAccountManagementService.listNotPage(sysAccountManagement));
    }

    /**
     * 根据id查询账户管理详情
     *
     * @param accountId 账户管理ID
     */
    //@SaCheckPermission("system:account:query")
    @GetMapping(value = "/{accountId}")
    public R<SysAccountManagement> getInfo(@PathVariable Long accountId) {
        return R.ok(sysAccountManagementService.getAccountManagementById(accountId));
    }

    /**
     * 新增账户管理
     *
     * @param sysAccountManagement
     * @return
     */
    //@SaCheckPermission("system:account:add")
    @Log(title = "新增账户管理", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Void> add(@Validated @RequestBody SysAccountManagement sysAccountManagement) {
        return toAjax(sysAccountManagementService.insertAccountManagement(sysAccountManagement));
    }

    /**
     * 修改账户管理
     *
     * @param sysAccountManagement
     * @return
     */
    //@SaCheckPermission("system:account:edit")
    @Log(title = "修改账户管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Void> edit(@Validated @RequestBody SysAccountManagement sysAccountManagement) {
        return toAjax(sysAccountManagementService.updateAccountManagement(sysAccountManagement));
    }

    /**
     * 删除账户管理
     *
     * @param accountId 账户管理ID
     */
    //@SaCheckPermission("system:account:remove")
    @Log(title = "删除账户管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{accountId}")
    public R<Void> remove(@PathVariable Long accountId) {
        return toAjax(sysAccountManagementService.deleteAccountManagement(accountId));
    }

    /**
     * 导出账户管理列表
     *
     * @param response
     * @param sysAccountManagement
     */
    @Log(title = "导出账户管理", businessType = BusinessType.EXPORT)
    //@SaCheckPermission("system:accountManagement:export")
    @GetMapping("/export")
    public void export(HttpServletResponse response, SysAccountManagement sysAccountManagement) {
        List<SysAccountManagementExport> list = sysAccountManagementService.selectAccountDeriveList(sysAccountManagement);
        ExcelUtil.exportExcel(list, "账户管理", SysAccountManagementExport.class, response);
    }

    /**
     * 账户管理下拉
     *
     */
    @GetMapping(value = "/down")
    public List<PullDown> getManagementDown() {
        return sysAccountManagementService.getManagementDown();
    }

}
